<?php
header("Content-Type: text/html; charset=iso-8859-1");
require_once('include.php');
$equipe = (!empty($_REQUEST['equipe'])) ? $_REQUEST['equipe'] : "";
$membre = (!empty($_REQUEST['membre'])) ? $_REQUEST['membre'] : "";
$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
if(check_admin() ||  $membre = check_cookie()){
	if($action == 'add'){
		$q = "select * from membre_equipes where membre_id = $membre and equipe_id = $equipe";
		$r = ExecRequete($q);
		if(!mysql_num_rows($r)){
			$q = "insert into membre_equipes (membre_id,equipe_id) values ($membre,$equipe)";
			if(ExecRequete($q)){
				echo 1;
				$q = "select nom,id_vbcll from equipes where id = $equipe";
				$r = ExecRequete($q);
				if($s = LigneSuivante($r)){
					$nom = $s->id_vbcll;
					if($nom == 'LNA') $nom = "M1";
					elseif($nom == 'M23F1') $nom = "M23F";
					$nom = strtolower($nom);
					$q = "select email from membres where id = $membre";
					$r = ExecRequete($q);
					if($s = LigneSuivante($r)){
						if(strpos($s->email,"@") !== FALSE) {
							mailing_list($nom,$s->email,1);
						}
					}
				}
			}
			else echo 0;
		}
		else echo 1;
	}
	elseif($action == 'del'){
		$q = "delete from membre_equipes where membre_id = '$membre' and equipe_id = '$equipe'";
		if(ExecRequete($q)){
			echo 1;
			$q = "select nom,id_vbcll from equipes where id = $equipe";
			$r = ExecRequete($q);
			if($s = LigneSuivante($r)){
				$nom = $s->id_vbcll;
				if($nom == 'LNA') $nom = "M1";
				elseif($nom == 'M23F1') $nom = "M23F";
				$nom = strtolower($nom);
				$q = "select email from membres where id = $membre";
				$r = ExecRequete($q);
				if($s = LigneSuivante($r)){
					if(strpos($s->email,"@") !== FALSE) {
						mailing_list($nom,$s->email,0);
					}
				}
			}
		}
		else echo 0;
	}
}
?>
